<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
      <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
<!--        <el-form-item label="提交工单的用户 ID" prop="orderSubmitterId">-->
<!--          <el-input v-model="formData.orderSubmitterId" placeholder="请输入提交工单的用户 ID" />-->
<!--        </el-form-item>-->
        <el-form-item label="提交工单的用户 姓名" prop="orderSubmitterName">
          <el-input v-model="formData.orderSubmitterName" placeholder="请输入提交工单的用户 姓名" />
        </el-form-item>
<!--        <el-form-item label="分配工单的用户 ID" prop="orderAssignerId">-->
<!--          <el-input v-model="formData.orderAssignerId" placeholder="请输入分配工单的用户 ID" />-->
<!--        </el-form-item>-->
        <el-form-item label="分配工单的用户 姓名" prop="orderAssignerName">
          <el-input v-model="formData.orderAssignerName" placeholder="请输入分配工单的用户 姓名" />
        </el-form-item>
<!--        <el-form-item label="处理工单的用户 ID" prop="orderProcessorId">-->
<!--          <el-input v-model="formData.orderProcessorId" placeholder="请输入处理工单的用户 ID" />-->
<!--        </el-form-item>-->
        <el-form-item label="处理工单的用户 姓名" prop="orderProcessorName">
          <el-input v-model="formData.orderProcessorName" placeholder="请输入处理工单的用户 姓名" />
        </el-form-item>
        <el-form-item label="工单类型" prop="orderType">
          <el-select v-model="formData.orderType" placeholder="请选择工单类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="工单分类" prop="orderCategory">
          <el-input v-model="formData.orderCategory" placeholder="请输入工单分类" />
        </el-form-item>
        <el-form-item label="工单优先级" prop="orderPriority">
          <el-input v-model="formData.orderPriority" placeholder="请输入工单优先级" />
        </el-form-item>
        <el-form-item label="工单文字描述">
          <Editor v-model="formData.orderDescription" :min-height="192"/>
        </el-form-item>
        <el-form-item label="图片的 URL" prop="imageUrls">
          <el-input v-model="formData.imageUrls" placeholder="请输入图片的 URL" />
        </el-form-item>
        <el-form-item label="视频的 URL" prop="videoUrls">
          <el-input v-model="formData.videoUrls" placeholder="请输入视频的 URL" />
        </el-form-item>
        <el-form-item label="工单创建（提交）时间" prop="orderCreateTime">
          <el-date-picker clearable v-model="formData.orderCreateTime" type="date" value-format="timestamp" placeholder="选择工单创建（提交）时间" />
        </el-form-item>
        <el-form-item label="工单分配时间" prop="orderAssignTime">
          <el-date-picker clearable v-model="formData.orderAssignTime" type="date" value-format="timestamp" placeholder="选择工单分配时间" />
        </el-form-item>
        <el-form-item label="工单开始处理时间" prop="orderProcessTime">
          <el-date-picker clearable v-model="formData.orderProcessTime" type="date" value-format="timestamp" placeholder="选择工单开始处理时间" />
        </el-form-item>
        <el-form-item label="预计完成时间" prop="orderCompletionTime">
          <el-date-picker clearable v-model="formData.orderCompletionTime" type="date" value-format="timestamp" placeholder="选择预计完成时间" />
        </el-form-item>
        <el-form-item label="实际完成时间" prop="orderActualTime">
          <el-date-picker clearable v-model="formData.orderActualTime" type="date" value-format="timestamp" placeholder="选择实际完成时间" />
        </el-form-item>
        <el-form-item label="工单处理状态" prop="orderStatus">
          <el-radio-group v-model="formData.orderStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否催办" prop="isUrged">
          <el-input v-model="formData.isUrged" placeholder="请输入是否催办" />
        </el-form-item>
        <el-form-item label="维修质量评分" prop="maintenanceQualityScore">
          <el-input v-model="formData.maintenanceQualityScore" placeholder="请输入维修质量评分" />
        </el-form-item>
        <el-form-item label="服务态度评分" prop="serviceAttitudeScore">
          <el-input v-model="formData.serviceAttitudeScore" placeholder="请输入服务态度评分" />
        </el-form-item>
        <el-form-item label="评价内容" prop="textEvaluation">
          <el-input v-model="formData.textEvaluation" placeholder="请输入评价内容" />
        </el-form-item>
        <el-form-item label="评价时间" prop="evaluationTime">
          <el-date-picker clearable v-model="formData.evaluationTime" type="date" value-format="timestamp" placeholder="选择评价时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as PropertyWorkOrderApi from '../../../../api/ipark/property/propertyworkorder';
import Editor from '@/components/Editor/index.vue';
export default {
  name: "PropertyWorkOrderForm",
  components: {
    Editor,
  },
  data() {
    return {
      // 弹出层标题
      dialogTitle: "",
      // 是否显示弹出层
      dialogVisible: false,
      // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
      formLoading: false,
      // 表单参数
      formData: {
        orderId: undefined,
        // orderSubmitterId: undefined,
        orderSubmitterName: undefined,
        // orderAssignerId: undefined,
        orderAssignerName: undefined,
        // orderProcessorId: undefined,
        orderProcessorName: undefined,
        orderType: undefined,
        orderCategory: undefined,
        orderPriority: undefined,
        orderDescription: undefined,
        imageUrls: undefined,
        videoUrls: undefined,
        orderCreateTime: undefined,
        orderAssignTime: undefined,
        orderProcessTime: undefined,
        orderCompletionTime: undefined,
        orderActualTime: undefined,
        orderStatus: undefined,
        isUrged: undefined,
        maintenanceQualityScore: undefined,
        serviceAttitudeScore: undefined,
        textEvaluation: undefined,
        evaluationTime: undefined,
      },
      // 表单校验
      formRules: {
      },
    };
  },
  methods: {
    /** 打开弹窗 */
    async open(id) {
      this.dialogVisible = true;
      this.reset();
      // 修改时，设置数据
      if (id) {
        this.formLoading = true;
        try {
          const res = await PropertyWorkOrderApi.getPropertyWorkOrder(id);
          this.formData = res.data;
          this.title = "修改工单";
        } finally {
          this.formLoading = false;
        }
      }
      this.title = "新增工单";
    },
    /** 提交按钮 */
    async submitForm() {
      // 校验主表
      await this.$refs["formRef"].validate();
      this.formLoading = true;
      try {
        const data = this.formData;
        // 修改的提交
        if (data.orderId) {
          await PropertyWorkOrderApi.updatePropertyWorkOrder(data);
          this.$modal.msgSuccess("修改成功");
          this.dialogVisible = false;
          this.$emit('success');
          return;
        }
        // 添加的提交
        await PropertyWorkOrderApi.createPropertyWorkOrder(data);
        this.$modal.msgSuccess("新增成功");
        this.dialogVisible = false;
        this.$emit('success');
      } finally {
        this.formLoading = false;
      }
    },
    /** 表单重置 */
    reset() {
      this.formData = {
        orderId: undefined,
        // orderSubmitterId: undefined,
        orderSubmitterName: undefined,
        // orderAssignerId: undefined,
        orderAssignerName: undefined,
        // orderProcessorId: undefined,
        orderProcessorName: undefined,
        orderType: undefined,
        orderCategory: undefined,
        orderPriority: undefined,
        orderDescription: undefined,
        imageUrls: undefined,
        videoUrls: undefined,
        orderCreateTime: undefined,
        orderAssignTime: undefined,
        orderProcessTime: undefined,
        orderCompletionTime: undefined,
        orderActualTime: undefined,
        orderStatus: undefined,
        isUrged: undefined,
        maintenanceQualityScore: undefined,
        serviceAttitudeScore: undefined,
        textEvaluation: undefined,
        evaluationTime: undefined,
      };
      this.resetForm("formRef");
    }
  }
};
</script>
